﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Things.Common;

namespace Things.ThingsWeb.Components
{
    public partial class GoodsList : System.Web.UI.UserControl
    {

        public DataSet DataSource
        {
            get;
            set;
        }

        public int ReaptColumns
        {
            get;
            set;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (ReaptColumns > 0)
                {
                    DataList1.RepeatColumns = ReaptColumns;
                }
                BindData();
            }
        }

        protected void BindData()
        {
            try
            {
                DataList1.DataSource = DataSource;
                DataList1.DataBind();
            }
            catch(Exception ex)
            {
                MessageBox.Show(this.Page, ex.Message);
            }
        }

        protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item)
            {
                ImageButton ibtAddToCart = (ImageButton)e.Item.FindControl("ibtAddToCart");
                if (ibtAddToCart != null)
                {
                    ibtAddToCart.CommandName = "JiaRuGouWuChe";
                }
            }
        }

        protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
        {
             string command = e.CommandName;
             switch (command)
             {
                 case "JiaRuGouWuChe":
                     // TO-DO
                     break;
                 default:
                     break;
             }
        }
    }
}